(function($) {

  var app = $.sammy('#content', function() {
    this.before(function(callback) {
      var context = this;
    });

    this.get('#/', function(context) {        
        $.ajax({
            url:'userData.php?method=get',
            dataType: 'json',
            async: false,
            success: function(response) {
                context.$element().html(ich.userData(response.oUser));
                $('#userDataSubmit').button();
            }
        });
    });
    
    this.post('#/', function(context) {
        $.ajax({
            url: 'userData.php?method=save',
            type: 'POST',
            dataType: 'json',
            data: this.params,
            async: false,
            success: function(oResponse) {
                if(oResponse.sStatus == "action_successfull") {
                    $('#status').text("Gespeichert!")
                    	.addClass("ui-state-highlight")
                    	.removeClass("ui-state-error");
                } else {
                    $('#status').text(oResponse.sReason)
                    	.addClass("ui-state-error")
                    	.removeClass("ui-state-highlight");
                }
            }
        });
    });
  });

  $(function() {
    app.run('#/');
  });

})(jQuery);
